import java.util.Arrays;

class Solution {
    public int[] missingTwo(int[] nums) {
        int n = nums.length;
        int ret = (n + 1) ^ (n + 2);
        // 把所有数异或到一起
        for (int i = 1; i <= nums.length; i++) {
            ret ^= i;
            ret ^= nums[i - 1];
        }
        // 找到 ret 中比特位为 1 的
        int x = 0;
        while (((ret >> x) & 1) != 1) {
            x++;
        }
        int[] ans = new int[2];
        for (int i = 0; i < nums.length + 2; i++) {
            if (i < nums.length) {
                if (((nums[i] >> x) & 1) == 1) {
                    ans[0] ^= nums[i];
                } else {
                    ans[1] ^= nums[i];
                }
            }
            if ((((i + 1) >> x) & 1) == 1) {
                ans[0] ^= (i + 1);
            } else {
                ans[1] ^= (i + 1);
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(Arrays.toString(solution.missingTwo(new int[]{1})));
    }
}